package cz.ctu.android.DriveCommunicator.activities;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import cz.ctu.android.DriveCommunicator.R;
import cz.ctu.android.DriveCommunicator.utils.DriverConstants;
import cz.ctu.android.DriveCommunicator.utils.DriverConstants.Users;
import cz.ctu.android.DriveCommunicator.utils.ImageMapper;
import cz.ctu.android.adapters.CustomListViewAdapter;
import cz.ctu.android.entity.RowItem;

public class NewMessageActivity extends Activity implements
OnItemClickListener{
	private ListView listView;
	private List<RowItem> rowItems = new ArrayList();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.receiverchooser);
		
		listView = (ListView) findViewById(R.id.choosereceiverlist);
		for (int i = 0; i < DriverConstants.numberOfUsers; i++) {
				RowItem item = new RowItem(ImageMapper.getImage(Users.values()[i].getID()),i+1,"",Users.values()[i].getJmeno()+" "+Users.values()[i].getPrijmeni());
				rowItems.add(item);
		}
		
		listView.setVisibility(3);
		
		CustomListViewAdapter adapter = new CustomListViewAdapter(this,
				R.layout.list_item, rowItems);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);
	}
	
	public void onItemClick(AdapterView<?> parent, View view, int position,long id) {	
		Bundle bundle = new Bundle();
		CustomListViewAdapter cw = (CustomListViewAdapter)parent.getAdapter();
		RowItem row = cw.getItem(position);
		bundle.putInt("idToLoad", row.getId());
		Intent newIntent = new Intent(this.getApplicationContext(), ReceiverConfirmActivity.class);
		newIntent.putExtras(bundle);
        startActivity(newIntent);
	}

	
}
